GBML manual / Backgrounds

background_count

How many project-created backgrounds currently EXIST (created and not yet destroyed) - hidden ones included.

Syntax

background_count() -> int

Returns

int

Description

How many project-created backgrounds currently exist - created and not yet destroyed - hidden ones included.

This is deliberately not how many are visible on screen right now. Existing and visible are two different numbers, bounded by two different, independent hardware budgets, and one function cannot honestly answer both. Not drawing a background in a frame (so it is hidden) never changes this count; only background_create/background_destroy do.

There is no project-facing "how many are visible" query today - and even your own project's half of that number would not actually answer the question you likely want it for, since the current room's own tile layers and shroud share the exact same hardware ceiling, and how many of those are visible right now is not something you can ask either. background_create's own nothing result is the one complete, honest way to learn whether room is left - not something to predict by checking a count first.

Example

var before = background_count();
backdrop = background_create(0, 0, ts_doc_dungeon);
if (background_count() != before) {
    background_priority(backdrop, 2);
}

Makes a background, then asks background_count() - it reports one more than before, even though nothing has drawn the background yet (a new background starts hidden). Only background_destroy brings the count back down.

On the GBA

Deliberately NOT how many are VISIBLE on screen right now - EXISTS and VISIBLE are two different numbers, bounded by two different, independent hardware budgets (background_create's own note), and one function cannot honestly answer both. Not drawing a background in a frame (so it is hidden) never changes this count; only background_create/background_destroy do. There is no project-facing "how many visible" query today, and publishing just your own project's half of that number would not actually answer the question you likely want it for: the CURRENT room's own tile layers/shroud share the exact same hardware ceiling, and how many of THOSE are visible right now is not a queryable number either. background_create's own `nothing` result is the one complete, honest way to learn whether room is left - not something to predict by checking a count first.

See also: background_createbackground_destroydraw_background